package com.pandas.community.dao;

import com.pandas.community.entity.LoginTicket;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

/**
 * Created by Liu Jiangang Cotter on 2021/3/24.
 */
@Mapper
@Repository
@Deprecated
public interface LoginTicketMapper {

    @Insert({
            "INSERT INTO login_ticket(user_id, ticket, status, expired) ",
            "VALUES (#{userid}, #{ticket}, #{status}, #{expired}) "
    })
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insertLoginTicket(LoginTicket loginTicket);

    @Select({
            "SELECT id, user_id, ticket, status, expired ",
            "FROM login_ticket WHERE ticket = #{ticket}"
    })
    //多次写入，默认取最近的?
    LoginTicket selectByTicket(String ticket);

    @Update({
            "<script>",
            "UPDATE login_ticket ",
            "SET status = #{status} WHERE ticket = #{ticket} ",
            "<if test=\"ticket!=null\">",
            "AND 1=1 ",
            "</if>",
            "</script>"
    })
    int updateStatus(String ticket, int status);

}
